﻿using Domain.Entity;
using Domain.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repositorys
{
    public class CFTKRepository : ICFTKRepository
    {
        private readonly MyDbContext myDbContext;

        public CFTKRepository(MyDbContext myDbContext)
        {
            this.myDbContext = myDbContext;
        }

		public async Task<bool> AddCFTKAsync(CFTK cFTK)
		{
			myDbContext.CFTK.Add(cFTK);
			return await myDbContext.SaveChangesAsync() > 0;
		}

		public async Task<bool> DeleteCFTKAsync(int id)
		{
			CFTK cFTK = new CFTK
			{
				FtkId = id
			};
			myDbContext.CFTK.Remove(cFTK);
			return await myDbContext.SaveChangesAsync() > 0;
		}

		public async Task<List<CFTK>> GetCFTKAsync()
		{
			return await myDbContext.CFTK.ToListAsync();
		}

		public async Task<List<CFTK>> GetCFTKAsyncById(string kid)
		{
			return await myDbContext.CFTK.Where(e => e.SecondKindId == kid).ToListAsync();
		}

		public async Task<bool> UpdateCFTKAsync(CFTK cFTK)
		{
			myDbContext.CFTK.Update(cFTK);
			return await myDbContext.SaveChangesAsync() > 0;
		}
	}
}
